package com.ladlee.parking.controller;

import com.ladlee.parking.entity.SecurityUser;
import com.ladlee.parking.sequence.seq.Sequence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(value = "/system")
public class SystemController {

    @Autowired
    Sequence paySequence;

    @GetMapping(value = "/indexInfo")
    public ModelAndView indexPage(ModelAndView modelAndView) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SecurityUser user = (SecurityUser) authentication.getPrincipal();
        modelAndView.setViewName("system/statistics");
        modelAndView.addObject("userInfo", user);
        return modelAndView;
    }

    @GetMapping(value = "/seq")
    public String getSequence() {
        return paySequence.nextNo();
    }
}
